package common;

import java.io.FileInputStream;
import java.io.IOException;
import java.net.URLDecoder;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class DBConnector {
    public static Connection getSQLServerConnection() {
        Connection conn = null;
        Properties pros = new Properties();
        String path = DBConnector.class.getClassLoader().getResource("jdbc.properties").getPath();
        try {
            path = URLDecoder.decode(path, "utf-8");
            FileInputStream fileInputStream = new FileInputStream(path);
            pros.load(fileInputStream);
            String user = pros.getProperty("user");
            String password = pros.getProperty("password");
            String url = pros.getProperty("url");
            String driverClass = pros.getProperty("driverClass");
            Class.forName(driverClass);
            conn = DriverManager.getConnection(url, user, password);
        } catch (IOException | SQLException | ClassNotFoundException e) {
            e.printStackTrace();
        }
        return conn;
    }
}
